<template>
	<view class="you-box">
		<view class="cont-input">
			<textarea placeholder="请输入你此刻的想法～～" v-model="describ"></textarea>
		</view>
		<view class="img-list">
			<image src="../../static/301.png" class="img" mode=""></image>
			<view class="bnt" @tap="upLoadImg">
				<image src="../../static/130.png" class="img" mode=""></image>
			</view>
		</view>
		<view class="y-type">
			谁可以看<view class="y-rihgt">
				<!-- <picker @change="bindPickerChange" :value="index" :range="array"> -->
				<view class="uni-input" @tap="setVal">{{array[index].label}}<image src="../../static/arrowL.png" class="img" mode=""></image></view>
				<!-- </picker> -->
			</view>
		</view>
		<view class="y-bnt" @tap="save">
			确认提交
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="p-content">
				<view class="txt" v-for="(item,index) in array" @tap="getVal(item,index)">
					{{item.label}}
				</view>
				<view class="txt c" @tap="close()">
					取消
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {createUserShow} from '@/api/user.js'
	export default {
		components: {
			
		},
		data() {
			return {
				index: 0,
				array: [{
					label:'公开',
					value: 1,
				},{
					label:'隐私',
					value: 2
				}],
				def: {},
				describ: '',
				opentype: ''
			};
		},
		onLoad(ops) {
			this.def = ops
		},
		methods: {
			close(){
				this.$refs.popup.close()
			},
			setVal(){
				this.$refs.popup.open('bottom')
			},
			getVal(item,index){
				this.opentype = item.value
				this.index = index
				this.close()
			},
			save(){
				createUserShow({describ:this.describ,opentype:this.opentype,orderId:this.def.id,subjectId:this.def.subjectld,pictures:''}).then((res) => {
					
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			// 图片上传
			upLoadImg(num) {
				let that = this;
				uni.chooseMedia({
					count: 1, // 默认9
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera', 'album'], // 可以指定来源是相册还是相机，默认二者都有
					success: function(source) {
						console.log('----------',source)
						console.log('00000000000000000',source.tempFiles[0].tempFilePath)
						if (source.tempFiles[0].size < 1024 * 1024 * 2) {
							uni.getImageInfo({
								src: source.tempFiles[0].tempFilePaths,
								success(res) {
									console.log('---------------------',res)
									// WUpload(
									// 	that.requestUrl,
									// 	that.uploadName,
									// 	that.token,
									// 	{
									// 		// token: uni.getStorageSync('token'),
									// 		// 根据接口要求修改对应的格式关键字
									// 		upload_type: that.imgType
									// 	},
									// 	source
									// )
									// .then(res1 => {
									// 	if (res1.state == true) {
									// 		let Res = res1.data;
									// 		Res.name = source.tempFilePaths[0];
									// 		if (num == 1) {
									// 			that.$emit('imgSuccess', Res); //返回上传成功的数据
									// 		} else {
									// 			that.$emit('fileSuccess', Res); //返回上传成功的数据
									// 		}
									// 		uni.showToast({
									// 			title: '上传成功'
									// 		});
									// 	} else {
									// 		uni.showToast({
									// 			title: '上传失败',
									// 			icon: 'none'
									// 		});
									// 	}
									// })
									// .catch(catchRes => {
									// 	console.log(catchRes);
									// 	uni.showToast({
									// 		title: '上传失败',
									// 		icon: 'none'
									// 	});
									// });
								},
								fail(error) {
									console.log(error);
								}
							});
						} else {
							uni.showToast({
								title: '图片过大，无法上传',
								icon: 'none'
							});
						}
					}
				});
			}
			
		}
	}
</script>

<style lang="less" scoped>
.you-box{
	padding-top: 34rpx;
	margin: 0 32rpx;
	.cont-input{
		height: 332rpx;
		border-radius: 40rpx;
		background: #FFFFFF;
		box-shadow: 0px 6px 16rpx 0px rgba(0, 0, 0, 0.1);
		textarea{
			padding: 20rpx;
			width: 94%;
		}
	}
	
	.img-list{
		margin-top: 34rpx;
		display: flex;
		.img{
			width: 226rpx;
			height: 226rpx;
		}
		.bnt{
			width: 226rpx;
			height: 226rpx;
			border: 2rpx dashed #d9dada;;
		}
	}
	
	.y-type{
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #666;
		margin-top: 160rpx;
		.y-rihgt{
			color: #333;
			float: right;
			.img{
				width: 48rpx;
				height: 48rpx;
				vertical-align: middle;
			}
		}
	}
	.y-bnt{
		background: #E4919D;
		height: 98rpx;
		border-radius: 50rpx;
		font-size: 36rpx;
		color: #fff;
		text-align: center;
		line-height: 98rpx;
		margin-top: 62rpx;
	}
}
</style>
